﻿using System;
using System.Collections.Generic;
using System.Text;
using TntOrm;
using TntOrm.Attributes;
using System.Data;

namespace SiteObjects
{
    [OrmTable( "USR_Role", "Роли", true )]
    public class Role : OrmDataBaseObject
    {
        private int? id_Role;
        
        [OrmTableField( "id_Role", SqlDbType.Int, false )]
        [OrmPrimaryKey]
        public int? RoleId
        {
            get { return id_Role; }
            set { id_Role = value; }
        }

        private string _Name;

        [OrmTableField( "Name", SqlDbType.VarChar, 50, false )]
        public string RoleName
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private string _Description;

        [OrmTableField( "Description", SqlDbType.NText, true )]
        public string RoleDescription
        {
            get { return _Description; }
            set { _Description = value; }
        }

        private User[] _RoleUsers;

        [OrmReference( typeof( User ), "Role", BelongType.HasMany )]
        public User[] RoleUsers
        {
            get 
            {
                if( _RoleUsers == null )
                {
                    User UO = new User( );
                    UO.Role = this;
                    _RoleUsers = UO.FetchLookUp <User>( );
                }

                return _RoleUsers;                            
            }
            set { _RoleUsers = value; }
        }


    }
}